package cn.wenhe9.novel.exception;

import cn.wenhe9.novel.constant.ResultCodeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 自定义业务异常，用于处理用户请求时，业务错误时抛出
 *
 * @author DuJinliang
 * 2022/5/18
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class NovelException extends RuntimeException {

    private final ResultCodeEnum resultCodeEnum;

    public NovelException(ResultCodeEnum resultCodeEnum) {
        // 不调用父类 Throwable的fillInStackTrace() 方法生成栈追踪信息，提高应用性能
        // 构造器之间的调用必须在第一行
        super(resultCodeEnum.getMessage(), null, false, false);
        this.resultCodeEnum = resultCodeEnum;
    }

}
